# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=nose
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.3.7
pkgrel=1
pkgdesc="A discovery-based unittest extension (mingw-w64)"
arch=('any')
license=('LGPL-2.1')
url="https://nose.readthedocs.io/"
depends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
install=${_realname}3-${CARCH}.install
source=("https://pypi.python.org/packages/source/n/nose/nose-${pkgver}.tar.gz")
sha256sums=('f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98')

prepare() {
  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}"
    msg "Python build for ${CARCH}"  
    cd "${srcdir}/python-build-${CARCH}"
    sed -i -e "s:man/man1:share/man/man1:g" setup.py
    ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})

  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
        -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done

  #rm -rf "${pkgdir}${MINGW_PREFIX}/share"
}
